<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>反馈</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="import" href="../header.html" id="page1">
		<!--标准mui.css-->
		
		<!--App自定义的css-->
		<!-- <link rel="stylesheet" type="text/css" href="../css/app.css" /> -->
		<link rel="stylesheet" type="text/css" href="../../css/app.css" />
		<link href="../../css/mui.picker.css" rel="stylesheet" />
		<link href="../../css/mui.poppicker.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../../css/feedback.css" />
		<style>
			h5 {
				margin: 5px 7px;
			}
			.pickimg {
				width: 80%;
				height: 80%;
			}
			ul {
				 list-style:none;
			}
			.listyle{
				width: 10%;
				height: 10%;
				 list-style-type:none;
				 float: left;
			}
				
		</style>
		<style>
			.mui-btn {
				font-size: 16px;
				padding: 8px;
				margin: 3px;
			}
			h5.mui-content-padded {
				margin-left: 3px;
				margin-top: 20px !important;
			}
			h5.mui-content-padded:first-child {
				margin-top: 12px !important;
			}
			.ui-alert {
				text-align: center;
				padding: 20px 10px;
				font-size: 16px;
			}
		</style>
	</head>

	<body>
		<header class="mui-bar mui-bar-nav">
			<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left"></a>
			<h1 class="mui-title">工单反馈</h1>
		</header>
		<div class="mui-content" id="rrapp">
			<div class="mui-content-padded " style="margin: 5px;">
				<div class="mui-input-row mui-content-padded" >
					<label>结果状态：</label>
					<input  id='showUserPicker4'  type="text"   readonly="readonly"></input>
				</div>
				<div class="mui-input-row mui-content-padded">
					<label>处理结果：</label>
					<input v-model="bussMaintainTask.resultContent" type="text"  ></input>
				</div>
				
				<div class="mui-input-row mui-content-padded">
					<label>附件：</label>
					<div class="feedback">
					   <!-- <input type="hidden" id="image-path" value=""> -->
					    <p><img style="margin-left: -6.15rem;" src="../../images/add.png" id="addnew"></p>
					    <div class="dynamic_images">  
						
					        <ul id="imgid">  
					            <li></li>   
					        </ul>  
					    </div>  
					</div>
					<div class="mui-button-row" style="clear: both;">
					    <button id="saveBtn" type="button" onclick="upload()" class="mui-btn mui-btn-primary">确认</button>&nbsp;&nbsp;
					    <button type="button" onclick="reset()" class="mui-btn mui-btn-danger">删除</button>
					</div>
				</div>
					<div class="mui-button-row">
						<button type="button" class="mui-btn mui-btn-danger" @click="save">确定</button>
						<button type="button" class="mui-btn mui-btn-danger" @click="fh">返回</button>
						
					</div>
				<!-- </form> -->
				
				
				
			</div>
		</div>
		
		<!--<script src="../js/mui.picker.min.js"></script>-->
		<script src='../../js/feedback.js'></script> 
		<script src="../../js/mui.picker.js"></script>
		<script src="../../js/mui.poppicker.js"></script>
		<script src="../../js/city.data.js" type="text/javascript" charset="utf-8"></script>
		<!-- <script src="../../js/jquery.js" type="text/javascript" charset="utf-8"></script> -->
		<script>
			 var files = []; 
			(function($, doc) {
				$.init();
				    
				    document.addEventListener("plusready", plusReady, false);  
				  
				    function plusReady() {
				        var wv = plus.webview.currentWebview();
				        document.getElementById("addnew").addEventListener("tap", function() {  
				            showActionSheet();//拍照还是相册  
				        });
				      
				        plus.nativeUI.closeWaiting();
				      
				    }  
				}(mui, document));
				 
				
				
				
				// 上传文件  
				function upload() {  
					console.log('1')
				    
				  var tokenmy = window.localStorage.getItem("token");
				    var task = plus.uploader.createUpload(baseUrl+'/fileAction/uploadhf?token='+tokenmy, {  
				            method: "POST"  
				        }, 
				        function(t, status) { //上传完成  
				            if (status == 200) {
								console.log(t.responseText);
				                var result =JSON.parse(t.responseText);
								if(result.code == 0){
									vm.bussMaintainTask.resultFileIds = result.id;
									mui.toast('上传成功');  
								}else{
									 console.log("上传失败：" + status);
								}
								
				                  
				            } else {  
				                console.log("上传失败：" + status);
				            }  
							console.log(t)
				        }
				    );  
				
				    for (var i = 0; i < files.length; i++) {
				        var f = files[i]; 
				        task.addFile(f.path, {  
				            key:f.name
				        });
				        
				       }
				    task.start();     
				      
				}  
				  
				// 添加文件  
				var index = 1;  
				var newUrlAfterCompress;  
				function appendFile(p) {  
				    files.push({ 
				        path: p,
				        name: "uploadkey_" + index
				    });  
				    index++;  
				}  
				// 产生一个随机数  
				function getUid() {  
				    return Math.floor(Math.random() * 100000000 + 10000000).toString();  
				}  
				  
				//删除上一张图片  
				function reset(){
					if(files.length>0){
					
					files.splice(files.length-1,1);
					console.log(files);
					var table = document.body.querySelector("#imgid");
					document.getElementById('imgid').lastChild.remove(); 
						
					}else{
					alert('请先上传图片');	
						
					}
					
				}
				  
				function galleryImgs() { // 从相册中选择图片  
				    plus.gallery.pick(function(e) {  
				        console.log("选择了"+e.files.length+"个图片");  
				        for (var i = 0; i < e.files.length; i++) {  
				            if (i < 9) {  
								 var li = document.createElement('li');
								 var htmls = "<li  class='listyle'><img class='pickimg' src='" + e.files[i] + "' /></li>";
								 li.innerHTML =  htmls;
								 var table = document.body.querySelector("#imgid");
								 table.appendChild(li);
				                // var do1 =  document.getElementById("imgid")
								 //do1.prepend("<li class='pickimg'><img src='" + e.files[i] + "' /></li>");  
								//(".dynamic_images ul").prepend("<li class='pickimg'><img src='" + e.files[i] + "' /></li>");  
				                var dstname="_downloads/"+getUid()+".jpg";//设置压缩后图片的路径  
				                newUrlAfterCompress=compressImage(e.files[i],dstname);  
				                appendFile(dstname);
				            }  
				        }  
				    }, function(e) {  
				        console.log("取消选择图片");  
				    }, {  
				        filter: "image",  
				        multiple: true  
				    });  
				}  
				  
				//压缩图片，这个比较变态的方法，无法return  
				function compressImage(src,dstname) {  
				    //var dstname="_downloads/"+getUid()+".jpg";  
				    plus.zip.compressImage({  
				            src: src,  
				            dst: dstname,  
				            overwrite:true,  
				            quality: 20  
				        },  
				        function(event) {  
				            //console.log("Compress success:"+event.target);  
				            return event.target;  
				        },  
				        function(error) {  
				            console.log(error);  
				            return src;  
				            //alert("Compress error!");  
				        });  
				      
				}  
				
				  
				function showActionSheet() {  
				    var bts = [{  
				        title: "拍照"  
				    }, {  
				        title: "从相册选择"  
				    }];  
				    plus.nativeUI.actionSheet({  
				            cancel: "取消",  
				            buttons: bts  
				        },  
				        function(e) {  
				            if (e.index == 1) {  
				                getImage();  
				            } else if (e.index == 2) {  
				                galleryImgs();  
				            }  
				        }  
				    );  
				}  
				//拍照  
				function getImage() {  
				    var cmr = plus.camera.getCamera();  
				    cmr.captureImage(function(p) {  
				        plus.io.resolveLocalFileSystemURL(p, function(entry) {  
				            var localurl = entry.toLocalURL(); //  
				            //$(".dynamic_images ul li").remove(".pickimg");  
				            $(".dynamic_images ul").prepend("<li class='pickimg'><img src='" + localurl + "' /></li>");  
				             var dstname="_downloads/"+getUid()+".jpg";//设置压缩后图片的路径  
				                newUrlAfterCompress=compressImage(localurl,dstname);  
				                appendFile(dstname); 
				        });  
				    });  
				}  
			
			

        function headImage(){
			debugger
			if (mui.os.plus) { 
			   var a = [{ 
				   title: "拍照" 
			   }, { 
				   title: "从手机相册选择" 
			   }]; 
			   plus.nativeUI.actionSheet({ 
				   title: "修改用户头像", 
				   cancel: "取消", 
				   buttons: a 
			   }, function(b) { /*actionSheet 按钮点击事件*/ 
				   switch (b.index) { 
					  case 0: 
							 break; 
					  case 1: 
							 getImage(); /*拍照*/ 
							 break; 
					  case 2: 
							 galleryImg();/*打开相册*/ 
							 break; 
					  default: 
							 break; 
					 } 
				  }) 
			 } 
		}
		//拍照 
		function getImage() { 
			var c = plus.camera.getCamera(); 
			c.captureImage(function(e) { 
			plus.io.resolveLocalFileSystemURL(e, function(entry) { 
				var s = entry.toLocalURL() + "?version=" + new Date().getTime(); 
				uploadHead(s); /*上传图片*/ 
			}, function(e) { 
				console.log("读取拍照文件错误：" + e.message); 
			}); 
			}, function(s) { 
			console.log("error" + s); 
			}, { 
			filename: "_doc/head.png" 
			}) 
		} 
        
		function galleryImg() { 
			plus.gallery.pick(function(a) { 
			plus.io.resolveLocalFileSystemURL(a, function(entry) { 
				plus.io.resolveLocalFileSystemURL("_doc/", function(root) { 
					debugger
				root.getFile("head.png", {}, function(file) { 
					//文件已存在 
					file.remove(function() { 
					console.log("file remove success"); 
					entry.copyTo(root, 'head.png', function(e) { 
						var e = e.fullPath + "?version=" + new Date().getTime(); 
						uploadHead(e); /*上传图片*/ 
						//变更大图预览的src 
						//目前仅有一张图片，暂时如此处理，后续需要通过标准组件实现 
						}, 
						function(e) { 
						console.log('copy image fail:' + e.message); 
						}); 
					}, function() { 
					console.log("delete image fail:" + e.message); 
					}); 
				}, function() { 
					//文件不存在 
					entry.copyTo(root, 'head.png', function(e) { 
						var path = e.fullPath + "?version=" + new Date().getTime(); 
						uploadHead(path); /*上传图片*/ 
					}, 
					function(e) { 
						console.log('copy image fail:' + e.message); 
					}); 
				}); 
				}, function(e) { 
				console.log("get _www folder fail"); 
				}) 
			}, function(e) { 
				console.log("读取拍照文件错误：" + e.message); 
			}); 
			}, function(a) {}, { 
			filter: "image" 
			}) 
		}; 
		
		
	
		var vm = new Vue({
				el:'#rrapp',
				data:{
					showList: true,
					title: null,
					insIndetailsugtion: {},
					 bussMaintainTask: {
					   id: 0,
					   handler: '',
					   equipmentId: '',
					   resultStatus: 0,
					   type: 0,
					   content: '',
					   gradeNum: '',
					   status: 0,
					 
					   resultContent: '',
					   resultFileIds: '',
					   sourceType: '',
					   resultFileIdsArr:[]
						
					 },
				},
				methods: {
					getm: function () {
							///44444444444444444444444444444
						/**
						 * 获取对象属性的值
						 * 主要用于过滤三级联动中，可能出现的最低级的数据不存在的情况，实际开发中需要注意这一点；
						 * @param {Object} obj 对象
						 * @param {String} param 属性名
						 */
						var _getParam = function(obj, param) {
							return obj[param] || '';
						};
						//普通示例
						var userPicker = new mui.PopPicker();
						
						
						userPicker.setData([
						{value:"0",text:"一切正常"},
						{value:"1",text:"恢复正常"},
						{value:"2",text:"延后处理"}
						]);
						var showUserPickerButton = document.getElementById('showUserPicker4');
						var userResult = document.getElementById('showUserPicker4');
						showUserPickerButton.addEventListener('tap', function(event) {
						
							userPicker.show(function(items) {
								userResult.value = items[0].text 
								vm.bussMaintainTask.resultStatus = items[0].value
							});
						}, false);
					},
					save : function(){
						vm.bussMaintainTask.id = T.p('gid');
						vm.bussMaintainTask.status = '2'
						mui.ajax(baseUrl+'/buss/bussmaintaintask/update',{
							data:JSON.stringify(vm.bussMaintainTask),
							//dataType:'json',//服务器返回json格式数据
							async: false,
							contentType: "application/json",
							type:'post',//HTTP请求类型
							//headers:{'Content-Type':'application/json'},	              
							success:function(data){
								if(data.code == 0){
									mui.toast('添加成功', {
										duration: 'long',
										type: 'div'
									})
									window.location.href="indexgd2.html";
								}else{
									mui.toast('添加失败', {
										duration: 'long',
										type: 'div'
									})
								}
								
							},error: function(xhr, type, errorThrown) {
								//异常处理；
								mui.toast('添加失败', {
									duration: 'long',
									type: 'div'
								})
							}
					})
					},
					fh:function(){
					   console.log('返回')
					   window.location.href = 'indexgd2.html'
					}
				},
				mounted:function(){
					this.getm();
					var id = T.p('gid');
					mui.get(baseUrl+"/buss/bussmaintaintask/info/"+id,function(data,status){
						console.log(data.bussMaintainTask)
						vm.bussMaintainTask = data.bussMaintainTask
					});
					
				}
			});
		</script>
	</body>

</html>